package cn.IT.Nf.Test.Servlet;

import cn.IT.Nf.Test.Dao.Impl.StaffsDaoImpl;
import cn.IT.Nf.Test.Dao.StaffsDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteStaffs")
public class DeleteStaffsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        StaffsDao staffsDao = new StaffsDaoImpl();
        int result = staffsDao.delete(Integer.parseInt(id));
        PrintWriter out = response.getWriter();
        if (result > 0) {
            out.write("删除成功");
            out.flush();
            out.close();
        }else {
            out.write("删除失败");
            out.flush();
            out.close();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
